﻿using System.Formats.Asn1;

namespace LeetCodeProject._0001_1000._001_100._21_30._023;

public class Solution
{
    public ListNode MergeKLists(ListNode[] lists)
    {
        List<int> help = new List<int>();
        for (int j = 0; j < lists.Length; j++)
        {
            ListNode ans = lists[j];
            while (ans != null)
            {
                help.Add(ans.val);
                ans = ans.next;
            }
        }

        help.Sort();
        ListNode res = new ListNode(0);
        int i = 0;
        ListNode helpNode = res;
        while (i < help.Count())
        {
            ListNode node = new ListNode(help[i++]);
            helpNode.next = node;
            helpNode = helpNode.next;
        }

        return res.next;
    }
}

public class ListNode
{
    public int val;
    public ListNode next;

    public ListNode(int val = 0, ListNode next = null)
    {
        this.val = val;
        this.next = next;
    }
}